home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / edm0407s.zip / STAT3SRC.ZIP / AFILE.HPP < prev    next >
Text File  |  1996-06-26  |  4KB  |  82 lines

  1. #ifndef _AFILE_HPP_
  2. #define _AFILE_HPP_
  3.  
  4. #define INCL_DOSFILEMGR
  5. #define INCL_ERRORS
  6.  
  7. #include <os2.h>
  8. #include <ibase.hpp>
  9. #include <istring.hpp>
  10.  
  11. #ifndef AFILE_FILE_NOT_OPEN
  12. #define AFILE_FILE_NOT_OPEN 100UL
  13. #endif
  14.  
  15. #ifndef AFILE_FILENAME_MISSING
  16. #define AFILE_FILENAME_MISSING 101UL
  17. #endif
  18.  
  19. #ifndef AFILE_NO_BUFFER_POINTER
  20. #define AFILE_NO_BUFFER_POINTER 102UL
  21. #endif
  22.  
  23. #ifndef AFILE_NO_BUFFER_SIZE
  24. #define AFILE_NO_BUFFER_SIZE 103UL
  25. #endif
  26.  
  27.  
  28. class AFile
  29.  
  30. {
  31.   public:
  32.     AFile(PVOID pBuffer = 0L, ULONG ulBufferSize = 0L);                       // constructor
  33.     ~AFile();                                                                 // destrcutor
  34.     virtual APIRET open (const PSZ pszFileName, const ULONG ulFileSize = 0L,  // opens a file
  35.                          const ULONG ulFileAttribute = FILE_NORMAL,
  36.                          const ULONG ulOpenFlag = FILE_OPEN | FILE_CREATE,
  37.                          const ULONG ulOpenMode = OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE,
  38.                          const PEAOP2 pEABuf = 0L);
  39.     virtual APIRET open (const IString & fileName, const ULONG ulFileSize = 0L, // opens a file
  40.                          const ULONG ulFileAttribute = FILE_NORMAL,
  41.                          const ULONG ulOpenFlag = FILE_OPEN | FILE_CREATE,
  42.                          const ULONG ulOpenMode = OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE,
  43.                          const PEAOP2 pEABuf = 0L);
  44.     virtual APIRET reOpen (const ULONG ulFileSize = 0L,                        // re-opens a file
  45.                            const ULONG ulFileAttribute = FILE_NORMAL,
  46.                            const ULONG ulOpenFlag = FILE_OPEN,
  47.                            const ULONG ulOpenMode = OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE,
  48.                            const PEAOP2 pEABuf = 0L);
  49.     virtual APIRET close (void);                                               // closes the file
  50.     APIRET read (PVOID pBuffer = 0L, ULONG ulBufferSize = 0UL);                // read data
  51.     APIRET write (PVOID pBuffer = 0L, ULONG ulBufferSize = 0UL);               // write data
  52.  
  53.     ULONG getFileSize (Boolean bRefresh = false);                              // returns the file size
  54.  
  55.     APIRET getLastDosError (void) const { return (m_lastDosError); };          // returns the last DOS error
  56.  
  57.     ULONG getActionTaken (void) const { return (m_ulActionTaken); };           // returns the action taken by DosOpen
  58.     ULONG getBytesRead (void) const   { return (m_ulBytesRead); };             // number of bytes read last time
  59.     ULONG getBytesWritten (void) const   { return (m_ulBytesWritten); };       // number of bytes written last time
  60.     Boolean isOpen (void) const { return (m_bIsOpen); };                       // is the file open
  61.  
  62.   private:
  63.     APIRET checkReadWrite(const PVOID pBuffer, const ULONG ulBufferSize);  // checking before reading/writing
  64.     virtual APIRET queryFileInfo (Boolean bRefresh = false);               // query the file info
  65.  
  66.     IString * m_pisFileName;      // the filename
  67.     Boolean m_bIsOpen;            // is the file open (true == open)
  68.     HFILE   m_hFile;              // file handle needed by the API-calls
  69.     ULONG   m_ulActionTaken,      // action taken by DosOpen
  70.             m_ulFileAttribute,    // file attributes
  71.             m_ulOpenFlag,         // open flags
  72.             m_ulOpenMode,         // open mode
  73.             m_ulBytesRead,        // bytes read last time
  74.             m_ulBytesWritten;     // bytes written last time
  75.     const ULONG m_ulBufferSize;   // initial buffer size passed to the constructor
  76.     PVOID const m_pBuffer;        // initial buffer passed to the constructor
  77.     FILESTATUS3 * m_pFilestatus3; // level 1 file status
  78.     APIRET m_lastDosError;        // last DOS error
  79. };
  80.  
  81. #endif //_AFILE_HPP_
  82.